const crypto = require('crypto')
/** 
  *@param   str 字符串 
   @param   key 秘钥 
  */
function cipher(str, key) {
    var decipher = crypto.createHash('sha256', key)
    if (key) {
        return decipher.update(str).digest()
    }
    return decipher.update(str).digest('hex')
};
function decipher(cipher, key) {
    var crypto = require('crypto');
var ciphera = crypto.createCipher('base64','InmbuvP6Z8')
var text = req.query.md5;
var crypted = ciphera.update(text,'utf8','hex')
crypted += ciphera.final('hex')
console.log(crypted)
var decipher = crypto.createDecipher('base64','InmbuvP6Z8')
var dec = decipher.update(crypted,'hex','utf8')
dec += decipher.final('utf8')
};


module.exports = {
    cipher,
    decipher
}